<template>
	<view >
		<my-search @click="goSearch">
			 
		</my-search>
		<view class="scroll-view-container" >
				<!-- 左侧列表选项 -->
			 <scroll-view scroll-y="true" :style="{height:wh+'px'}"  class="left-scroll-view">
					<view class="left-scroll-view-item " v-for="(item1,index1) in cateList" :key="index1" :class="{active:active==index1}" @click="activeChange(index1)">{{item1.cat_name}}</view>
					
			 </scroll-view>
			 
			 <scroll-view scroll-y="true" :style="{height:wh+'px'}" class="right-scroll-view" :scrollTop="scrollTop">
					<view class="cate-1v2" v-for="(item2,index2) in cateLevel2" :key="index2">
						<!-- 二级标题 -->
							<view class="cate-1v2-title">/ {{item2.cat_name}} / </view>
						<!-- 三级内容 -->	
						<view class="cate-1v2-list">
							<view v-for="(item3,index3) in item2.children" :key="index3" class="cate-1v2-item" @click="gotoGoodsList(item3)">
									<image :src="item3.cat_icon" ></image>
									<text class="cate-lv3-title">{{item3.cat_name}}</text>
							</view>	
						</view>
					</view>
					
			 </scroll-view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins:[badgeMix],
		data() {
			return {
				wh:0,
				cateList:[],
				active:0,
				//二级分类列表
				cateLevel2:[],
				scrollTop:0
			};
		},
		
		onLoad(){
			const wh=uni.getSystemInfoSync().windowHeight - 50
			this.wh=wh
			this.getCateList()
		},
		methods:{
		 async getCateList(){
			 const {data:res} = await uni.$http.get('api/public/v1/categories')
			 console.log(res);
			 if(res.meta.status!=200) return uni.$showMsg()
			 this.cateList=res.message 
			 this.cateLevel2 = res.message[0].children
			
			// 接口变更要手动改数据	
			 // this.cateLevel2.forEach(item=>{
				// 	item.children.forEach(item1=>{
				// 		item1.cat_icon=item1.cat_icon.replace('-dev','-web')
				// 	})
			 // })
			},
			//改变激活项，并更新二级列表
			activeChange(index){
				this.active=index
				this.cateLevel2=this.cateList[index].children
				this.scrollTop = this.scrollTop === 0?1:0
				// 接口变更要手动改数据
				// this.cateLevel2.forEach(item=>{
				// 					item.children.forEach(item1=>{
				// 						item1.cat_icon=item1.cat_icon.replace('-dev','-web')
				// 	})
				// })
			},
			gotoGoodsList(item3){
					console.log(item3);
					uni.navigateTo({
						url:`/subpkg/goods_list/goods_list?cid=${item3.cat_id}`
					})
			},
			goSearch(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="scss">
.scroll-view-container{
	display: flex;
	.left-scroll-view{
		width: 120px;
			.left-scroll-view-item{
					font-size: 12px;
					line-height: 60px;
					text-align: center;
					position: relative;
					
					&.active{
						background-color: #ffffff;
							&::before{
								position: absolute;
								content:'';
								width:3px;
								height: 30px;
								background-color: #c00000;
								top: 50%;
								transform: translateY(-50%);
								left: 0;
							}
					}
					
			}
			
	}
	
}

.cate-1v2-title{
	font-size: 12px;
	font-weight: bolder;
	text-align: center;
	padding: 15px 0;
}

.cate-1v2-list{
	display: flex;
	flex-wrap: wrap;
		.cate-1v2-item{
			width: 33.33%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			margin-bottom: 10px;
			font-size: 12px;
				image{
					width: 60px;
					height: 60px;
					border-radius: 5px;
				}
				text{
					padding-top: 5px;
				}
		}
}

</style>
